package com.eliauk.demo.controller.read;

import com.alibaba.excel.EasyExcel;
import com.eliauk.demo.dao.DemoDAO;
import com.eliauk.demo.entity.read.CellDataReadDemoData;
import com.eliauk.demo.utils.excel.listener.Demo9DataListener;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/demo9")
public class demo9Controller {
    /**
     * 读取公式和单元格类型
     * @param file excel 文件
     * @return
     * @throws IOException
     */
    @PostMapping("/import")
    public String importData(MultipartFile file) throws IOException {
        InputStream in  = file.getInputStream();
        EasyExcel.read(in, CellDataReadDemoData.class,new Demo9DataListener(new DemoDAO()))
                .sheet()
                .doRead();
        return "success";
    }
}
